package love.yuanmeng.guetcoalsystem.service.impl;

/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:lzl
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/10/11 11:40
 */


import love.yuanmeng.guetcoalsystem.mapper.EnterpriseInfoMapper;
import love.yuanmeng.guetcoalsystem.mapper.UserMapper;
import love.yuanmeng.guetcoalsystem.pojo.EnterpriseInfo;
import love.yuanmeng.guetcoalsystem.pojo.User;
import love.yuanmeng.guetcoalsystem.service.RegisterService;
import love.yuanmeng.guetcoalsystem.vo.RegisterVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RegisterServiceImpl implements RegisterService {

    @Resource
    private EnterpriseInfoMapper enterpriseInfoMapper;

    @Resource
    private UserMapper userMapper;

    //添加企业信息
    public int addEnterpriseInfo(EnterpriseInfo enterpriseInfo) {
        return enterpriseInfoMapper.insert(enterpriseInfo);
    }

    //添加用户信息
    public int addUserInfo(User userInfo){
        return userMapper.insert(userInfo);
    }

    //业务处理
    @Override
    public int doService(RegisterVo registerVo) {
        EnterpriseInfo enterpriseInfo=registerVo.getEnterpriseInfo();
        User userInfo=registerVo.getUserInfo();
        if(enterpriseInfo.getEnterpriseType().equals("供应商")){
            enterpriseInfo.setEnterpriseType("1");
            userInfo.setStatus("1");
        }else{
            enterpriseInfo.setEnterpriseType("0");
            userInfo.setStatus("0");
        }
        int result = addEnterpriseInfo(enterpriseInfo);
        if(result==0) return 0;
        String enterpriseId=enterpriseInfo.getEnterpriseId()+"";
        userInfo.setEnterpriseid(enterpriseId);
        userInfo.setAvailable("待审核");
        int userId = addUserInfo(userInfo);
        return userId;
    }
}
